package c.x.jy.bean.event.listener;

import java.math.BigDecimal;
import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

import c.x.jy.bean.event.OrderCommissionEvent;
import c.x.jy.dao.dto.TeacherEntityDto;
import c.x.jy.dao.entity.BusinessEntity;
import c.x.jy.dao.entity.BusinessWalletEntity;
import c.x.jy.dao.entity.MemberEntity;
import c.x.jy.dao.entity.MemberWalletEntity;
import c.x.jy.dao.entity.OrderBillEntity;
import c.x.jy.dao.entity.OrderCommisionEntity;
import c.x.jy.dao.entity.OrderEntity;
import c.x.jy.dao.entity.TeacherEntity;
import c.x.jy.dao.model.OrderForm;
import c.x.jy.service.config.BusinessConfigService;
import c.x.jy.service.entity.form.CommisionConfig;
import c.x.jy.service.service.BusinessService;
import c.x.jy.service.service.BusinessWalletService;
import c.x.jy.service.service.MemberService;
import c.x.jy.service.service.MemberWalletService;
import c.x.jy.service.service.OrderBillService;
import c.x.jy.service.service.OrderCommisionService;
import c.x.jy.service.service.TeacherService;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@Component
public class OrderCommissionListener {

	@Autowired
	private MemberService memberService;

	@Autowired
	private BusinessService businessService;

	@Autowired
	private BusinessWalletService businessWalletService;

	@Autowired
	private MemberWalletService memberWalletService;

	@Autowired
	private BusinessConfigService businessConfigService;
	@Autowired
	private OrderCommisionService orderCommisionService;
	@Autowired
	private TeacherService teacherService;
	
	@Autowired
	private OrderBillService orderBillService;
	

	/**
	 * 普通订单 咨询及提问订单 一笔会员交易参与分佣,会员自己折扣权9%， 代理商后台直接认证会员18%（含会员推广会员9%差价） ，
	 * 会员推广的老师接单得到5% ， 接单老师得到60% ，平台余留8% ； 也可以理解为一个单子有下单人A , 推广下单人A的B，推广（直营）B的代理商C,
	 * 以及平台D分成 ， 以及商家老师甲，和推广商家甲的乙，六人产于分成
	 * 
	 * @param orderCommissionEvent
	 */

	@Async
	@EventListener
	public void paySuccess(OrderCommissionEvent orderCommissionEvent) {
		log.info("开始分佣！！");
		OrderEntity order = (OrderEntity) orderCommissionEvent.getData();
		log.info("分员分佣！！");// 会员自己折扣权9%， 代理商后台直接认证会员18%（含会员推广会员9%差价）

		if (order == null || !(order.getServiceType().equals(OrderForm.orderType.consult.getType())
				&& order.getServiceType().equals(OrderForm.orderType.ask.getType()))) {
			log.info("非普通订单 退出!");
			return;
		}
		
		
		OrderBillEntity orderbill = order.getOrderBill();
		orderbill =		orderBillService.selectByorderForUpdate(orderbill.getId());
		if(orderbill.getCommisionStatus().equals(1)) {
			log.info("订单已分佣 退出!");
			return;
		}
		orderbill.setCommisionStatus(1);
		orderBillService.updateById(orderbill);
		CommisionConfig commisionConfig = businessConfigService.selsetCommisionConfig();
		// 平台分
		BigDecimal platformComm = new BigDecimal(100);
		// 代理分佣
		BigDecimal agentComm = new BigDecimal(commisionConfig.getAgentslef()) .add(new BigDecimal(commisionConfig.getMemberReferences()));
		MemberEntity member = memberService.getById(order.getMemberId());

		if (member.getMemberLevel() == 1) {

			platformComm=		platformComm.subtract(new BigDecimal(commisionConfig.getMemberslef()));
			// 会员的本人分佣
			OrderCommisionEntity ocommision = new OrderCommisionEntity();
			ocommision.setAction(1);
			ocommision.setCreateDate(new Date());
			ocommision.setOrderId(order.getId());
			ocommision.setPayeeId(member.getId());
			ocommision.setPayeeType(3);
			ocommision.setPrice(new BigDecimal(commisionConfig.getMemberslef()).multiply(orderbill.getActualPrice())
					.divide(new BigDecimal(100)));
			orderCommisionService.save(ocommision);
			// member = memberService.selectMemberByIdForUpdate(order.getMemberId());

			MemberWalletEntity mw = memberWalletService.selectMemberWalletByMemberIdFOrUpdate(order.getMemberId());
			mw.setCommissionBalance(mw.getCommissionBalance().add(ocommision.getPrice()));
			mw.setTotalCommission(mw.getTotalCommission().add(ocommision.getPrice()));
			memberWalletService.updateById(mw);
		}
		MemberEntity parentMember = null;
		if (member.getParentId() != null && member.getParentId() > 0)
			parentMember = memberService.getById(member.getParentId());

		if (parentMember != null && parentMember.getMemberLevel() == 1) {
			platformComm=platformComm.subtract(new BigDecimal(commisionConfig.getMemberReferences()));
			agentComm=		agentComm.subtract(new BigDecimal(commisionConfig.getMemberReferences()));
			// 推荐会员的上级分佣
			OrderCommisionEntity ocommision = new OrderCommisionEntity();
			ocommision.setAction(1);
			ocommision.setCreateDate(new Date());
			ocommision.setOrderId(order.getId());
			ocommision.setPayeeId(parentMember.getId());
			ocommision.setPayeeType(3);
			ocommision.setPrice(new BigDecimal(commisionConfig.getMemberReferences())
					.multiply(orderbill.getActualPrice()).divide(new BigDecimal(100)));
		
			orderCommisionService.save(ocommision);

			MemberWalletEntity mw = memberWalletService.selectMemberWalletByMemberIdFOrUpdate(parentMember.getId());
			mw.setCommissionBalance(mw.getCommissionBalance().add(ocommision.getPrice()));
			mw.setTotalCommission(mw.getTotalCommission().add(ocommision.getPrice()));
			memberWalletService.updateById(mw);
		}

		// BusinessEntity business= businessService.getById( order.getBusinessId());

		if (agentComm != null) {
			// 代理玄商分佣 最高18% 9 +9 +9
			platformComm=	platformComm.subtract(agentComm);
			OrderCommisionEntity ocommision = new OrderCommisionEntity();
			ocommision.setAction(1);
			ocommision.setCreateDate(new Date());
			ocommision.setOrderId(order.getId());
			ocommision.setPayeeId(order.getBusinessId());
			ocommision.setPayeeType(1);
			ocommision.setPrice(agentComm.multiply(orderbill.getActualPrice()).divide(new BigDecimal(100)));
			;
			orderCommisionService.save(ocommision);
			BusinessWalletEntity bw = businessWalletService
					.selectbusinessWallentByBusinessIdForUpdate(order.getBusinessId());
			bw.setCommissionBalance(bw.getCommissionBalance().add(ocommision.getPrice()));
			bw.setTotalCommission(bw.getTotalCommission().add(ocommision.getPrice()));
			businessWalletService.updateById(bw);
		}

		/**
		 * 
		 */
		log.info("大师分佣！！");// 会员推广的老师接单得到5% ， 接单老师得到60% ，平台余留8% ；

		TeacherEntity teacher = teacherService.selectById(order.getTeacherId());
		// 大师本人分佣
		BigDecimal teacherCommision = new BigDecimal(commisionConfig.getTeacherslef());
		// if(teacher!=null) {
		MemberEntity teachermember = memberService.getById(teacher.getMemberId());

		MemberEntity parentTeacher = null;
		// 平台分佣
	 
		if (teachermember.getParentId() != null && teachermember.getParentId() > 0)
			parentTeacher = memberService.getById(teachermember.getParentId());

		if (parentTeacher != null && parentTeacher.getMemberLevel() == 1) {
			platformComm=	platformComm.subtract(new BigDecimal(commisionConfig.getTeacherReferences()));
			// 推广大师的上级分佣
			OrderCommisionEntity ocommision = new OrderCommisionEntity();
			ocommision.setAction(1);
			ocommision.setCreateDate(new Date());
			ocommision.setOrderId(order.getId());
			ocommision.setPayeeId(parentTeacher.getId());
			ocommision.setPayeeType(3);
			ocommision.setPrice(new BigDecimal(commisionConfig.getTeacherReferences())
					.multiply(orderbill.getActualPrice()).divide(new BigDecimal(100)));

			orderCommisionService.save(ocommision);
			MemberWalletEntity mw = memberWalletService.selectMemberWalletByMemberIdFOrUpdate(parentTeacher.getId());
			mw.setCommissionBalance(mw.getCommissionBalance().add(ocommision.getPrice()));
			mw.setTotalCommission(mw.getTotalCommission().add(ocommision.getPrice()));
			memberWalletService.updateById(mw);

		}

		// }

		if (teacherCommision != null) {
			// BigDecimal platformComm=
			platformComm = platformComm.subtract(teacherCommision);
			// 大师分佣
			OrderCommisionEntity ocommision = new OrderCommisionEntity();
			ocommision.setAction(1);
			ocommision.setCreateDate(new Date());
			ocommision.setOrderId(order.getId());
			ocommision.setPayeeId(teachermember.getId());
			ocommision.setPayeeType(2);
			ocommision.setPrice(teacherCommision.multiply(orderbill.getActualPrice()).divide(new BigDecimal(100)));
			
			orderCommisionService.save(ocommision);

			MemberWalletEntity mw = memberWalletService.selectMemberWalletByMemberIdFOrUpdate(teachermember.getId());
			mw.setCommissionBalance(mw.getCommissionBalance().add(ocommision.getPrice()));
			mw.setTotalCommission(mw.getTotalCommission().add(ocommision.getPrice()));
			memberWalletService.updateById(mw);
		}

		// 平台分佣
		if (platformComm != null) {
			OrderCommisionEntity ocommision = new OrderCommisionEntity();
			ocommision.setAction(1);
			ocommision.setCreateDate(new Date());
			ocommision.setOrderId(order.getId());
			ocommision.setPayeeId(0l);
			ocommision.setPayeeType(0);
			ocommision.setPrice(platformComm.multiply(orderbill.getActualPrice()).divide(new BigDecimal(100)));
		
			orderCommisionService.save(ocommision);
		}

	}

	/**
	 * 认证分佣 认证订单
	 * 
	 * @param orderCommissionEvent
	 */

	@Async
	@EventListener
	public void payMemberCertSuccess(OrderCommissionEvent orderCommissionEvent) {
		log.info("开始分佣！！");
		OrderEntity order = (OrderEntity) orderCommissionEvent.getData();
		log.info("分员分佣！！");// 会员自己折扣权9%， 代理商后台直接认证会员18%（含会员推广会员9%差价）
		if (order == null || !order.getServiceType().equals(OrderForm.orderType.member_cert.getType())) {
			log.info("非会员认证订单 退出!");
			return;
		}

		OrderBillEntity orderbill = order.getOrderBill();
		orderbill =		orderBillService.selectByorderForUpdate(orderbill.getId());
		if(orderbill.getCommisionStatus().equals(1)) {
			log.info("订单已分佣 退出!");
			return;
		}
		orderbill.setCommisionStatus(1);
		orderBillService.updateById(orderbill);
		CommisionConfig commisionConfig = businessConfigService.selsetCommisionConfig();
		// 平台分佣比例
		BigDecimal platformComm = new BigDecimal(100); 
		// 代理分佣
		BigDecimal agentComm = new BigDecimal(commisionConfig.getAgentslef()) .add(new BigDecimal(commisionConfig.getMemberReferences()));
		MemberEntity member = memberService.getById(order.getMemberId());

		MemberEntity parentMember = null;
		if (member.getParentId() != null && member.getParentId() > 0)
			parentMember = memberService.getById(member.getParentId());

		if (parentMember != null && parentMember.getMemberLevel() == 1) {
			// 平台减会员
			platformComm=	platformComm.subtract(new BigDecimal(commisionConfig.getMemberReferences()));
			// 代理减会员
			agentComm=		agentComm.subtract(new BigDecimal(commisionConfig.getMemberReferences()));
			// 推荐会员的上级分佣
			OrderCommisionEntity ocommision = new OrderCommisionEntity();
			ocommision.setAction(1);
			ocommision.setCreateDate(new Date());
			ocommision.setOrderId(order.getId());
			ocommision.setPayeeId(parentMember.getId());
			ocommision.setPayeeType(3);
			ocommision.setPrice(new BigDecimal(commisionConfig.getMemberReferences())
					.multiply(orderbill.getActualPrice()).divide(new BigDecimal(100)));
	
			orderCommisionService.save(ocommision);

			MemberWalletEntity mw = memberWalletService.selectMemberWalletByMemberIdFOrUpdate(parentMember.getId());
			mw.setCommissionBalance(mw.getCommissionBalance().add(ocommision.getPrice()));
			mw.setTotalCommission(mw.getTotalCommission().add(ocommision.getPrice()));
			memberWalletService.updateById(mw);
		}

		// BusinessEntity business= businessService.getById( order.getBusinessId());

		if (agentComm != null) {
			// 代理分佣
			platformComm=		platformComm.subtract(agentComm);// 平台减代理
			OrderCommisionEntity ocommision = new OrderCommisionEntity();
			ocommision.setAction(1);
			ocommision.setCreateDate(new Date());
			ocommision.setOrderId(order.getId());
			ocommision.setPayeeId(order.getBusinessId());
			ocommision.setPayeeType(1);
			ocommision.setPrice(agentComm.multiply(orderbill.getActualPrice()).divide(new BigDecimal(100)));
		
			orderCommisionService.save(ocommision);
			BusinessWalletEntity bw = businessWalletService
					.selectbusinessWallentByBusinessIdForUpdate(order.getBusinessId());
			bw.setCommissionBalance(bw.getCommissionBalance().add(ocommision.getPrice()));
			bw.setTotalCommission(bw.getTotalCommission().add(ocommision.getPrice()));
			businessWalletService.updateById(bw);
		}

		// 平台分佣
		if (platformComm != null) {
			OrderCommisionEntity ocommision = new OrderCommisionEntity();
			ocommision.setAction(1);
			ocommision.setCreateDate(new Date());
			ocommision.setOrderId(order.getId());
			ocommision.setPayeeId(0l);
			ocommision.setPayeeType(0);
			ocommision.setPrice(platformComm.multiply(orderbill.getActualPrice()).divide(new BigDecimal(100)));
		
			orderCommisionService.save(ocommision);
		}

	}
	
	
	/**
	 * 闪测订单分佣1
	 * 
	 * @param orderCommissionEvent
	 */

	@Async
	@EventListener
	public void payquick1Success(OrderCommissionEvent orderCommissionEvent) {
		log.info("开始分佣！！");
		OrderEntity order = (OrderEntity) orderCommissionEvent.getData();
		log.info("分员分佣！！");// 会员自己折扣权9%， 代理商后台直接认证会员18%（含会员推广会员9%差价）
		if (order == null || !order.getServiceType().equals(OrderForm.orderType.quick.getType())) {
			log.info("非会员闪测订单订单 退出!");
			return;
		}

		OrderBillEntity orderbill = order.getOrderBill();
		if(orderbill.getCommisionStatus()!=0) {
			log.info("订单已分佣 1退出!");
			return;
		}
	
		orderbill =		orderBillService.selectByorderForUpdate(orderbill.getId());
		if(orderbill.getCommisionStatus()!=0) {
			log.info("订单已分佣1 退出!");
			return;
		}

		orderbill.setCommisionStatus(2);
		orderBillService.updateById(orderbill);
		
		CommisionConfig commisionConfig = businessConfigService.selsetCommisionConfig();
		// 平台分佣比例
		BigDecimal platformComm = new BigDecimal(100);
		// 代理分佣
		BigDecimal agentComm = new BigDecimal(commisionConfig.getAgentslef()) .add(new BigDecimal(commisionConfig.getMemberReferences()));
		MemberEntity member = memberService.getById(order.getMemberId());
		if (member.getMemberLevel() == 1) {

			platformComm=	platformComm.subtract(new BigDecimal(commisionConfig.getMemberslef()));
			// 会员的本人分佣
			OrderCommisionEntity ocommision = new OrderCommisionEntity();
			ocommision.setAction(1);
			ocommision.setCreateDate(new Date());
			ocommision.setOrderId(order.getId());
			ocommision.setPayeeId(member.getId());
			ocommision.setPayeeType(3);
			ocommision.setPrice(new BigDecimal(commisionConfig.getMemberslef()).multiply(orderbill.getActualPrice())
					.divide(new BigDecimal(100)));
			orderCommisionService.save(ocommision);
			// member = memberService.selectMemberByIdForUpdate(order.getMemberId());

			MemberWalletEntity mw = memberWalletService.selectMemberWalletByMemberIdFOrUpdate(order.getMemberId());
			mw.setCommissionBalance(mw.getCommissionBalance().add(ocommision.getPrice()));
			mw.setTotalCommission(mw.getTotalCommission().add(ocommision.getPrice()));
			memberWalletService.updateById(mw);
		}
		

		MemberEntity parentMember = null;
		if (member.getParentId() != null && member.getParentId() > 0)
			parentMember = memberService.getById(member.getParentId());

		if (parentMember != null && parentMember.getMemberLevel() == 1) {
			// 平台减会员
		//	platformComm.subtract(new BigDecimal(commisionConfig.getMemberReferences()));
			// 代理减会员
			agentComm=	agentComm.subtract(new BigDecimal(commisionConfig.getMemberReferences()));
			// 推荐会员的上级分佣
			OrderCommisionEntity ocommision = new OrderCommisionEntity();
			ocommision.setAction(1);
			ocommision.setCreateDate(new Date());
			ocommision.setOrderId(order.getId());
			ocommision.setPayeeId(parentMember.getId());
			ocommision.setPayeeType(3);
			ocommision.setPrice(new BigDecimal(commisionConfig.getMemberReferences())
					.multiply(orderbill.getActualPrice()).divide(new BigDecimal(100)));

			orderCommisionService.save(ocommision);

			MemberWalletEntity mw = memberWalletService.selectMemberWalletByMemberIdFOrUpdate(parentMember.getId());
			mw.setCommissionBalance(mw.getCommissionBalance().add(ocommision.getPrice()));
			mw.setTotalCommission(mw.getTotalCommission().add(ocommision.getPrice()));
			memberWalletService.updateById(mw);
		}

		// BusinessEntity business= businessService.getById( order.getBusinessId());

		if (agentComm != null) {
			// 代理分佣
		//	platformComm.subtract(agentComm);// 平台减代理
			OrderCommisionEntity ocommision = new OrderCommisionEntity();
			ocommision.setAction(1);
			ocommision.setCreateDate(new Date());
			ocommision.setOrderId(order.getId());
			ocommision.setPayeeId(order.getBusinessId());
			ocommision.setPayeeType(1);
			ocommision.setPrice(agentComm.multiply(orderbill.getActualPrice()).divide(new BigDecimal(100)));
			orderCommisionService.save(ocommision);
			BusinessWalletEntity bw = businessWalletService
					.selectbusinessWallentByBusinessIdForUpdate(order.getBusinessId());
			bw.setCommissionBalance(bw.getCommissionBalance().add(ocommision.getPrice()));
			bw.setTotalCommission(bw.getTotalCommission().add(ocommision.getPrice()));
			businessWalletService.updateById(bw);
		}
 

	}
	
	
	
	/**
	 * 闪测订单分佣2
	 * 
	 * @param orderCommissionEvent
	 */

	@Async
	@EventListener
	public void payquick2Success(OrderCommissionEvent orderCommissionEvent) {
		log.info("开始分佣！！");
		OrderEntity order = (OrderEntity) orderCommissionEvent.getData();
		log.info("分员分佣！！");// 会员自己折扣权9%， 代理商后台直接认证会员18%（含会员推广会员9%差价）
		if (order == null || !order.getServiceType().equals(OrderForm.orderType.quick.getType())) {
			log.info("非会员闪测订单订单 退出!");
			return;
		}

		OrderBillEntity orderbill = order.getOrderBill();
		if(orderbill.getCommisionStatus()!=2) {
			log.info("订单分佣2 退出!");
			return;
		}
		orderbill =		orderBillService.selectByorderForUpdate(orderbill.getId());
		if(!orderbill.getCommisionStatus().equals(2)) {
			log.info("订单已分佣2 退出!");
			return;
		}
		orderbill.setCommisionStatus(1);
		orderBillService.updateById(orderbill);
		
		CommisionConfig commisionConfig = businessConfigService.selsetCommisionConfig();
		// 平台分佣比例
		BigDecimal platformComm = new BigDecimal(100); 
		BigDecimal agentComm = new BigDecimal(commisionConfig.getAgentslef()) .add(new BigDecimal(commisionConfig.getMemberReferences()));
		MemberEntity member = memberService.getById(order.getMemberId());
		if (member.getMemberLevel() == 1) {

			platformComm=	platformComm.subtract(new BigDecimal(commisionConfig.getMemberslef()));
		}
		
		MemberEntity parentMember = null;
		if (member.getParentId() != null && member.getParentId() > 0)
			parentMember = memberService.getById(member.getParentId());

		if (parentMember != null && parentMember.getMemberLevel() == 1) {
			// 平台减会员
			platformComm=		platformComm.subtract(new BigDecimal(commisionConfig.getMemberReferences()));
			// 代理减会员
			agentComm=		agentComm.subtract(new BigDecimal(commisionConfig.getMemberReferences()));
		}
		
		platformComm=	platformComm.subtract(agentComm);// 平台减代理

		/**
		 * 
		 */
		log.info("大师分佣！！");// 会员推广的老师接单得到5% ， 接单老师得到60% ，平台余留8% ；

		TeacherEntity teacher = teacherService.selectById(order.getTeacherId());
		// 大师本人分佣
		BigDecimal teacherCommision = new BigDecimal(commisionConfig.getTeacherslef());
		// if(teacher!=null) {
		MemberEntity teachermember = memberService.getById(teacher.getMemberId());

		MemberEntity parentTeacher = null;
		// 平台分佣
		// BigDecimal platformComm= new BigDecimal (100).subtract( new BigDecimal
		// (commisionConfig.getAgentslef()).add(new BigDecimal
		// (commisionConfig.getMemberReferences())).add(new BigDecimal
		// (commisionConfig.getMemberslef())).add(new BigDecimal
		// (commisionConfig.getTeacherslef())).add(new BigDecimal
		// (commisionConfig.getTeacherReferences())));
		if (teachermember.getParentId() != null && teachermember.getParentId() > 0)
			parentTeacher = memberService.getById(teachermember.getParentId());

		if (parentTeacher != null && parentTeacher.getMemberLevel() == 1) {
			platformComm=	platformComm.subtract(new BigDecimal(commisionConfig.getTeacherReferences()));
			// 推广大师的上级分佣
			OrderCommisionEntity ocommision = new OrderCommisionEntity();
			ocommision.setAction(1);
			ocommision.setCreateDate(new Date());
			ocommision.setOrderId(order.getId());
			ocommision.setPayeeId(parentTeacher.getId());
			ocommision.setPayeeType(3);
			ocommision.setPrice(new BigDecimal(commisionConfig.getTeacherReferences())
					.multiply(orderbill.getActualPrice()).divide(new BigDecimal(100)));

			orderCommisionService.save(ocommision);
			MemberWalletEntity mw = memberWalletService.selectMemberWalletByMemberIdFOrUpdate(parentTeacher.getId());
			mw.setCommissionBalance(mw.getCommissionBalance().add(ocommision.getPrice()));
			mw.setTotalCommission(mw.getTotalCommission().add(ocommision.getPrice()));
			memberWalletService.updateById(mw);

		}

		// }

		if (teacherCommision != null) {
			// BigDecimal platformComm=
			platformComm = platformComm.subtract(teacherCommision);
			// 大师分佣
			OrderCommisionEntity ocommision = new OrderCommisionEntity();
			ocommision.setAction(1);
			ocommision.setCreateDate(new Date());
			ocommision.setOrderId(order.getId());
			ocommision.setPayeeId(teachermember.getId());
			ocommision.setPayeeType(2);
			ocommision.setPrice(teacherCommision.multiply(orderbill.getActualPrice()).divide(new BigDecimal(100)));
			
			orderCommisionService.save(ocommision);

			MemberWalletEntity mw = memberWalletService.selectMemberWalletByMemberIdFOrUpdate(teachermember.getId());
			mw.setCommissionBalance(mw.getCommissionBalance().add(ocommision.getPrice()));
			mw.setTotalCommission(mw.getTotalCommission().add(ocommision.getPrice()));
			memberWalletService.updateById(mw);
		}

		// 平台分佣
		if (platformComm != null) {
			OrderCommisionEntity ocommision = new OrderCommisionEntity();
			ocommision.setAction(1);
			ocommision.setCreateDate(new Date());
			ocommision.setOrderId(order.getId());
			ocommision.setPayeeId(0l);
			ocommision.setPayeeType(0);
			ocommision.setPrice(platformComm.multiply(orderbill.getActualPrice()).divide(new BigDecimal(100)));
		
			orderCommisionService.save(ocommision);
		}
		
	}
	
	
	
	

}
